package com.itheima.sc.web.pms;

import com.itheima.sc.config.ComException;
import com.itheima.sc.pojo.pms.Product;
import com.itheima.sc.result.Result;
import com.itheima.sc.service.pms.ProductService;
import com.itheima.sc.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("product")
public class ProductController {
    @Autowired
    private ProductService productService;

    //创建商品
    @PostMapping("create")
    public Result create(@RequestBody Product productParam){
        productService.create(productParam);
        return Result.success(null);
    }

    //查询商品
    @GetMapping("list")
    public Result list(Integer brandId, String keyword, Integer productCategoryId,
                       String productSn, Integer publishStatus, Integer verifyStatus,
                       @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                       @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize) {
        PageResult pageResult = productService.listAll(brandId, keyword, pageNum, pageSize, productCategoryId, productSn, publishStatus, verifyStatus);
        return Result.success(pageResult);
    }

    //根据商品名称或货号模糊查询
    @GetMapping("simpleList")
    public Result simpleList(String keyword){
        List<Product> productList = productService.simpleList(keyword);
        return Result.success(productList);
    }

    //批量修改删除状态
    @PostMapping("update/deleteStatus")
    public Result updateDeleteStatus(@RequestParam Integer deleteStatus,
                                     @RequestParam List<Integer> ids){

        productService.updateDeleteStatus(deleteStatus,ids);
        return Result.success(null);
    }

    //批量设为新品
    @PostMapping("update/newStatus")
    public Result updateNewStatus(@RequestParam Integer newStatus,
                                      @RequestParam List<Integer> ids){
        productService.updateNewStatus(newStatus,ids);
        return Result.success(null);
    }

    //批量上下架商品
    @PostMapping("update/publishStatus")
    public Result updatePublishStatus(@RequestParam Integer publishStatus,
                                  @RequestParam List<Integer> ids){
        productService.updatePublishStatus(publishStatus,ids);
        return Result.success(null);
    }

    //批量推荐商品
    @PostMapping("update/recommendStatus")
    public Result updateRecommendStatus(@RequestParam Integer recommendStatus,
                                        @RequestParam List<Integer> ids){
        productService.updateRecommendStatus(recommendStatus,ids);
        return Result.success(null);
    }

    //批量修改审核状态  todo:找不到接口

    //更新商品
    @PostMapping("update/{id}")
    public Result updateById(@PathVariable Integer id,@RequestBody Product productParam){
        productService.updateById(id,productParam);
        return Result.success(null);
    }

    //根据商品id获取商品编辑信息
    @GetMapping("updateInfo/{id}")
    public Result updateInfoById(@PathVariable Integer id){
        Product product = productService.updateInfoById(id);
        return Result.success(product);
    }














}
